package br.dot.droid.manager;

import android.app.Activity;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import br.dot.droid.util.Constants;
import br.dot.droid.vo.User;

public class UserManager {
	
	private static Activity view;
	
	public static void setActivityParent(Activity parent){
		view = parent;
	}
	
	public static User getUser() {
		SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(view);
		String userName = preferences.getString(Constants.USER_NAME_PARAM, null);
		String password = preferences.getString(Constants.USER_PASSWORD_PARAM, null);
		return new User(userName, password);
	}
	
	public static void login(String user, String password) {
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(view);
		SharedPreferences.Editor spe = prefs.edit();
		spe.putString(Constants.USER_NAME_PARAM, user);
		spe.putString(Constants.USER_PASSWORD_PARAM, password);
		spe.commit(); 
	}

}
